<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let p = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('ok')
            }, 1000)
        })
        p.then(value => {
            // console.log(xxx);
            throw '未知错误'
        }).then(value => {
            console.log(111);
        }).then(value => {
            console.log(222);
        }).catch(reason => {
            console.log(reason);//可捕获到throw错误信息
        })
        // Promise异常穿透
        // (1)当使用promise的then链式调用时,可以在最后指定失败的回调
        // (2)前面任何操作出了异常,都会传到最后失败的回调中处理(类似node的全局捕获错误级别中间件err)
    </script>
</body>

</html>